package com.wl.tp;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

/**
 * 投屏server
 * @author EDZ
 *
 */
public class TPServer {
	public static final int DEFAULT_PORT = 10001;
	
	public static void main(String[] args) {
		TCPServer server = new TCPServer(DEFAULT_PORT) {
			
			@Override
			public void onServerStop() {
				System.out.println(">>>>>>> onServerStop");
			}
			
			@Override
			public void onReceive(SocketTransceiver client, byte[] data) {
//				try {
////					String str = new String(data, "UTF-8");
////					printInfo(client, "Send data:" + str);
////					client.send(str);
//				} catch (UnsupportedEncodingException e) {
//					e.printStackTrace();
//				}
				
			}
			
			@Override
			public void onDisconnect(SocketTransceiver client) {
				printInfo(client, "Disconnected.");
			}
			
			@Override
			public void onConnectFailed() {
				System.out.println("Connect failed.");
			}
			
			@Override
			public void onConnect(SocketTransceiver client) {
				printInfo(client, "Connect Succ..");
			}
		};
		
		System.out.println("Server start ...");
		server.start();
	}

	static void printInfo(SocketTransceiver st, String msg) {
		System.out.println("Client " + st.getInetAddress().getHostAddress() + " : " + msg);
	}
}
